<template>
  <div style="padding:0px;">
    <el-form :model="dialogForm" ref="dialogForms" :rules="rules" :label-width="formLabelWidth">
      <el-tabs v-model="activeName" type="card">
        <el-tab-pane label="图片信息" name="1" :index="1">
          <el-form-item label="上游购销合同">
            <!-- qiniuImage:七牛图片对象  packJson:上传张数大小等参数配置  id:七牛组件id canDelete:是否可操作删除图片 -->
            <qiniu :qiniuImage="qiniuImage" :packJson="packJson" :id="qiniuImage.id" :canDelete="isAdd.bool"></qiniu>
          </el-form-item>
          <el-form-item label="定金凭证">
            <qiniu :qiniuImage="qiniuImage1" :packJson="packJson" :id="qiniuImage1.id" :canDelete="isAdd.bool"></qiniu>
          </el-form-item>
          <el-form-item label="供应商收款账号">
            <qiniu :qiniuImage="qiniuImage2" :packJson="packJson1" :id="qiniuImage2.id" :canDelete="isAdd.bool"></qiniu>
          </el-form-item>
          <el-form-item label="提车地址及联系人">
            <qiniu :qiniuImage="qiniuImage3" :packJson="packJson1" :id="qiniuImage3.id" :canDelete="isAdd.bool"></qiniu>
          </el-form-item>

          <el-form-item label="补充图片">
            <qiniu :qiniuImage="qiniuImage6" :id="qiniuImage6.id" :canDelete="false"></qiniu>
          </el-form-item>
        </el-tab-pane>
        <el-tab-pane label="基本信息" name="2" :index="2">
          <el-form-item label="订单号">
            <el-input v-model="dialogForm.orderNumber" auto-complete="off" disabled></el-input>
          </el-form-item>
          <el-form-item label="申请时间">
            <el-input v-model="dialogForm.addTime" auto-complete="off" disabled></el-input>
          </el-form-item>
          <el-form-item label="经销商名称">
            <el-input v-model="dialogForm.dealerName" auto-complete="off" disabled></el-input>
          </el-form-item>
          <el-form-item label="订单类型" prop="type">
            <el-select v-model="dialogForm.type" placeholder="请选择订单类型" :disabled="!isAdd.bool">
              <el-option label="请选择订单类型" value="">
              </el-option>
              <el-option v-for="(item, index) in orderType" :label="item" :value="index-0" :key="index">
              </el-option>
            </el-select>
          </el-form-item>



          <el-form-item label="业务员" prop="businessSysUsersId">
            <el-select v-model="dialogForm.businessSysUsersId" placeholder="请选择业务员" :disabled="!isAdd.bool">
              <el-option label="请选择业务员" value="">
              </el-option>
              <el-option v-for="(item,index) in yewuyuan" :label="item.realname" :value="item.id" :key="index">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="地推员">
            <el-select v-model="dialogForm.pushSysUsersId" placeholder="请选择地推员" :disabled="!isAdd.bool">
              <el-option label="请选择地推员" value="">
              </el-option>
              <el-option v-for="(item,index) in ditui" :label="item.realname" :value="item.id" :key="index">
              </el-option>
            </el-select>
          </el-form-item>


          <el-form-item label="资金方">
            <el-select v-model.number="dialogForm.funderId" placeholder="请选择资金方" :disabled="!isAdd.bool" v-on:change="getSpvUser()">
              <el-option label="请选择资金方" value="">
              </el-option>
              <el-option v-for="(item,index) in selectFunder" :label="item.realname" :value="item.id" :key="index">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="SPV">
            <el-input :value="selectSpvUser.realname" auto-complete="off" disabled></el-input>
          </el-form-item>
          <el-form-item label="补充说明">
            <el-input type="textarea" :rows=3 v-model="dialogForm.supplementExplain" auto-complete="off" disabled></el-input>
          </el-form-item>
        </el-tab-pane>
        <el-tab-pane label="车辆信息" name="3" :index="3">
          <Linkage v-if="dialogForm.carBrandId||dialogForm.carBrandId==null" :pinpaiId="dialogForm.carBrandId" :zipinpaiId="dialogForm.carSubBrandId"
            :chexiId="dialogForm.carSeriesId" :chexingId="dialogForm.carTypeId" :isDisabled="!isAdd.bool||dialogForm.priceStatus==2||dialogForm.priceStatus==3"
            v-on:receive-brand-data="receiveBrandData" :formLabelWidth="formLabelWidth" :carOrderId="carOrderId"></Linkage>
          <el-form-item label="汽车车规">
            <el-input v-model="dialogForm.specificationName" auto-complete="off" disabled></el-input>
          </el-form-item>
          <el-form-item label="汽车数量" class="half" prop="amount">
            <el-input type="tel" :maxlength="9" v-model.number="dialogForm.amount" auto-complete="off" :disabled="!isAdd.bool||dialogForm.priceStatus==2||dialogForm.priceStatus==3"></el-input>

          </el-form-item>
          <el-form-item label="汽车颜色" class="half" prop="color">
            <el-input :maxlength="10" v-model="dialogForm.color" auto-complete="off" :disabled="!isAdd.bool"></el-input>
          </el-form-item>
          <el-form-item label="指导价/配置" prop="carConfig">
            <el-input type="textarea" :rows=3 v-model="dialogForm.carConfig" auto-complete="off" :disabled="!isAdd.bool" :maxlength="100"></el-input>
          </el-form-item>
          <el-form-item label="价格审核备注">
            <el-input type="textarea" :rows=3 v-model="dialogForm.priceRemark" auto-complete="off" disabled></el-input>
          </el-form-item>
          <!-- prop="totalPrice" -->
          <el-form-item label="购车总价格" prop="totalPrice" class="currency">
            <el-input v-model="dialogForm.totalPrice" @blur="FormatTwo('totalPrice')" :maxlength="12" auto-complete="off" :disabled="!isAdd.bool||dialogForm.priceStatus==2||dialogForm.priceStatus==3"></el-input>
            <span class="convertCurrency">{{dialogForm.totalPrice|convertCurrency}}</span>
          </el-form-item>
          <el-form-item label="垫资金额" prop="paymentAmount" class="currency">
            <el-input v-model="dialogForm.paymentAmount" @blur="FormatTwo('paymentAmount')" :maxlength="12" auto-complete="off" :disabled="!isAdd.bool"></el-input>
            <span class="convertCurrency">{{dialogForm.paymentAmount|convertCurrency}}</span>
            <!--  <el-input type="number"  v-model="dialogForm.paymentAmount " auto-complete="off" :disabled="!isAdd.bool" ></el-input> -->
          </el-form-item>
          <el-form-item label="定金金额" prop="earnest" class="currency">
            <el-input v-model="dialogForm.earnest" @blur="FormatTwo('earnest')" :maxlength="12" auto-complete="off" :disabled="!isAdd.bool"></el-input>
            <span class="convertCurrency">{{dialogForm.earnest|convertCurrency}}</span>
          </el-form-item>
          <el-form-item label="保证金金额" prop="_deposit" class="currency">
            <el-input v-model="_deposit" :disabled="true"></el-input>
            <span class="convertCurrency">{{_deposit|convertCurrency}}</span>
          </el-form-item>
          <el-form-item label="垫资比例" class="half" prop="earnest">
            <el-input type="text" :value="(((dialogForm.paymentAmount-0)/(dialogForm.totalPrice-0)*100-0).toFixed(2)||'')+'%'" auto-complete="off"
              disabled class="colorRed"></el-input>
          </el-form-item>

          <el-form-item label="当前利率" class="half" prop="interestRate">

            <el-input type="text" v-model="dialogForm.interestRate" @blur="FormatInterestRate('interestRate')" auto-complete="off" :maxlength=8
              :disabled="!isAdd.bool"></el-input>

          </el-form-item>

          <el-form-item label="借款时长" prop="durationId">
            <el-select v-model="dialogForm.durationId" placeholder="请选择借款时长" :disabled="!isAdd.bool">
              <el-option label="请选择借款时长" value=""> </el-option>
              <el-option v-for="(item,index) in dialogForm.carOrderDurationList" :label="item.description" :value="item.id" :key="index">
              </el-option>
            </el-select>
          </el-form-item>



          <el-form-item label="车辆基本信息是否确认" prop="priceStatus">
            <el-radio-group v-model.number="priceCheckStatus" :disabled="(!isAdd.bool||dialogForm.priceStatus==2||dialogForm.priceStatus==3)">
              <el-radio :label="1">否
              </el-radio>
              <el-radio :label="3" v-if="dialogForm.priceStatus == 3">是</el-radio>
              <el-radio :label="2" v-else="dialogForm.priceStatus == 2">是</el-radio>
            </el-radio-group>
          </el-form-item>

        </el-tab-pane>
        <el-tab-pane label="上游购销信息" name="4" :index="4">
          <!-- <el-form-item label="合同上游名称"  prop="supplierName">
				      <el-input :maxlength="30" v-model="dialogForm.supplierName " auto-complete="off" :disabled="!isAdd.bool" ></el-input>
				    </el-form-item> -->

          <el-form-item label="合同上游名称" prop="supplierName">
            <el-select v-model.number="dialogForm.supplierName" placeholder="请选择合同名称" filterable :disabled="!isAdd.bool">
              <el-option label="请选择合同名称" value=""> </el-option>
              <el-option v-for="(item,index) in upSupplier" :key="index" :label="item.name" :value="item.name">
              </el-option>
            </el-select>

          </el-form-item>


          <el-form-item label="提车省" prop="supplierCityPid">

            <el-select v-model.number="dialogForm.supplierCityPid" placeholder="请选择提车省" :disabled="!isAdd.bool" v-on:change="getCity()">
              <el-option label="请选择提车省" value=""> </el-option>
              <el-option v-for="(item,index) in selectProvince" :key="item.index" :label="item.name" :value="item.nid">
              </el-option>
            </el-select>

          </el-form-item>
          <el-form-item label="提车市" prop="supplierCityNid">
            <el-select v-model.number="dialogForm.supplierCityNid" placeholder="请选择提车市" :disabled="!isAdd.bool">

              <el-option v-for="(item,index) in selectCity" :key="item.index" :label="item.name" :value="item.nid">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="提车具体地址" prop="supplierAddress">
            <el-input :maxlength="30" v-model="dialogForm.supplierAddress" auto-complete="off" :disabled="!isAdd.bool"></el-input>
          </el-form-item>

          
          <template>
              <!-- <el-form-item label="提车联系人" prop="supplierPerson">
              <el-select v-model="dialogForm.supplierPerson" placeholder="请选择提车联系人" :disabled="dialogForm.supplierName==null" @change="carPhone(dialogForm.supplierPerson)">
                <el-option v-for="(item,index) in carPerson" :key="index" :label="item.name" :value="item.name">
                </el-option>
              </el-select>
            </el-form-item> -->

            <el-form-item label="提车联系人">
            <el-input :maxlength="20" v-model="dialogForm.supplierPerson" auto-complete="off" :disabled="!isAdd.bool"></el-input>
          </el-form-item>
        </template>
        




          <el-form-item label="联系人手机号" prop="supplierPhone">
            <el-input :maxlength="11" v-model="dialogForm.supplierPhone" auto-complete="off" :disabled="!isAdd.bool"></el-input>
          </el-form-item>

          <el-form-item label="收款账户名1" prop="accountName">
            <el-input :maxlength="30" v-model="dialogForm.accountName" auto-complete="off" :disabled="!isAdd.bool"></el-input>
          </el-form-item>
          <el-form-item label="开户行名称1" prop="openningBank">
            <el-input :maxlength="30" v-model="dialogForm.openningBank" auto-complete="off" :disabled="!isAdd.bool"></el-input>
          </el-form-item>
          <el-form-item label="收款账号1" prop="accountNumber">
            <el-input v-model="dialogForm.accountNumber" auto-complete="off" :disabled="!isAdd.bool" :maxlength="30"></el-input>
          </el-form-item>
          <!-- <el-form-item label="备用收款信息"  >
				      <el-button  type="primary" @click="activeShow=!activeShow">{{activeShow?"收 起":"展 开"}}</el-button>
				    </el-form-item>
				    <div v-if="activeShow" > -->

          <el-form-item label="收款账户名2">
            <el-input :maxlength="20" v-model="dialogForm.accountNameBak" auto-complete="off" :disabled="!isAdd.bool"></el-input>
          </el-form-item>
          <el-form-item label="开户行名称2">
            <el-input :maxlength="30" v-model="dialogForm.openningBankBak" auto-complete="off" :disabled="!isAdd.bool"></el-input>
          </el-form-item>
          <el-form-item label="收款账号2">
            <el-input :maxlength="30" v-model="dialogForm.accountNumberBak" auto-complete="off" :disabled="!isAdd.bool"></el-input>
          </el-form-item>
          <!-- </div> -->
          <el-form-item label="打款备注">
            <!-- prop="remark" -->
            <el-input :maxlength="100" type="textarea" :rows=3 v-model="dialogForm.remark" auto-complete="off" :disabled="!isAdd.bool"></el-input>
          </el-form-item>
          <el-form-item label="上游信息是否确认" prop="supplierInfoStatus">
            <el-radio-group v-model.number="dialogForm.supplierInfoStatus" :disabled="!isAdd.bool">
              <el-radio :label="0">否</el-radio>
              <el-radio :label="1">是</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-tab-pane>
        <el-tab-pane label="初审审核结果" name="5" :index="5">

          <el-form-item label="上游购销合同审核结果">
            <el-input :maxlength="50" v-model="dialogForm.orderAuditResults.upperReacherExamineResult" auto-complete="off" :disabled="!isAdd.bool"></el-input>
          </el-form-item>
          <el-form-item label="定金凭证审核结果">
            <el-input :maxlength="50" v-model="dialogForm.orderAuditResults.earnestExamineResult" auto-complete="off" :disabled="!isAdd.bool"></el-input>
          </el-form-item>
          <el-form-item label="供应商名称">
            <el-input :maxlength="50" v-model="dialogForm.orderAuditResults.supplierEstablishName" auto-complete="off" :disabled="!isAdd.bool"></el-input>
          </el-form-item>
          <el-form-item label="供应商成立日期">
            <el-date-picker :editable="false" style="width:100%;" v-model="dialogForm.orderAuditResults.supplierEstablishTime" type="date"
              placeholder="选择供应商成立日期" :disabled="!isAdd.bool" :picker-options="endDateOpt">
            </el-date-picker>
            <!-- <el-input  v-model="dialogForm.orderAuditResults.supplierEstablishTime" auto-complete="off" :disabled="!isAdd.bool" ></el-input> -->
          </el-form-item>
          <el-form-item label="供应商审核结果">
            <el-input :maxlength="50" v-model="dialogForm.orderAuditResults.establishExamineResult" auto-complete="off" :disabled="!isAdd.bool"></el-input>
          </el-form-item>
          <el-form-item label="供应商资质图片">
            <qiniu :qiniuImage="qiniuImage4" :packJson="packJson2" :id="qiniuImage4.id" :canDelete="isAdd.bool"></qiniu>
          </el-form-item>
          <el-form-item label="资源商名称">
            <el-input :maxlength="50" v-model="dialogForm.orderAuditResults.resourceProviderName" auto-complete="off" :disabled="!isAdd.bool"></el-input>
          </el-form-item>
          <el-form-item label="资源商成立日期">
            <el-date-picker :editable="false" style="width:100%;" v-model="dialogForm.orderAuditResults.resourceProviderEstablishTime"
              type="date" placeholder="选择资源商成立日期" :disabled="!isAdd.bool" :picker-options="endDateOpt">
            </el-date-picker>
            <!-- <el-input  v-model="dialogForm.orderAuditResults.resourceProviderEstablishTime" auto-complete="off" :disabled="!isAdd.bool" ></el-input> -->
          </el-form-item>
          <el-form-item label="资源商审核结果">
            <el-input :maxlength="50" v-model="dialogForm.orderAuditResults.resourceProviderExamineResult" auto-complete="off" :disabled="!isAdd.bool"></el-input>
          </el-form-item>
          <el-form-item label="资源商资质图片">
            <qiniu :qiniuImage="qiniuImage5" :packJson="packJson2" :id="qiniuImage5.id" :canDelete="isAdd.bool"></qiniu>
          </el-form-item>
          <el-form-item label="审核结果">
            <el-input :maxlength="100" type="textarea" :rows=3 v-model="dialogForm.dataChangeRecord" auto-complete="off" :disabled="!isAdd.bool"></el-input>
          </el-form-item>
          <el-form-item label="提车地址审核结果">
            <el-input :maxlength="50" v-model="dialogForm.orderAuditResults.carAddressExamineResult" auto-complete="off" :disabled="!isAdd.bool"></el-input>
          </el-form-item>

          <el-form-item label="审核人员" class="half">
            <el-input v-model="dialogForm.orderAuditResults.firstExamineResultName" auto-complete="off" disabled></el-input>
          </el-form-item>
          <el-form-item label="审核时间" class="half">
            <el-input v-model="dialogForm.orderAuditResults.firstExamineResultTime" auto-complete="off" disabled></el-input>
          </el-form-item>
        </el-tab-pane>

      </el-tabs>
      <div style="text-align:right;margin-top:15px;">
        <el-button @click="returnBack">返 回</el-button>
        <el-button v-if="dialogForm.statusVO != orderStatusFirstinstance&&isAdd.bool" type="success" @click="saveOrder()">暂 存</el-button>
        <el-button v-if="(dialogForm.statusVO === orderStatusFirstaudit || dialogForm.statusVO === orderStatusSecondreviewfailed)&&isAdd.bool"
          type="primary" @click="submitConfirmForm('dialogForms')">提 交</el-button>
      </div>
    </el-form>
    <div id="getFocus" tabindex="0"> </div>
  </div>
</template>

<script>
  import qiniu from '@/views/qiniu/upload';
  import agentHttp from '@/utils/agentHttp.js';
  import {
    require,
    prop,
    phone,
    decimalTwo,
    decimalFour,
    isChinese,
    length30,
    length100,
    decimal,
    max100
  } from '@/utils/rules.js'
  // import brandSelect from '@/views/brandSelect'
  import Linkage from '@/views/brandSelect/linkage.vue'
  export default {
    created() {
      this.queryAuditOrderInfo()
    },

    components: {
      qiniu,
      Linkage
    },
    data() {
      return {
        endDateOpt: {
          disabledDate(time) {
            return time.getTime() > Date.now()
          }
        },
        rules: {
          'totalPrice': [require('购车总价格', {
            validator: decimalTwo,
            trigger: "blur"
          })],
          'paymentAmount': [require('垫资金额', {
            validator: decimalTwo,
            trigger: "blur"
          })],
          'earnest': [require('定金金额', {
            validator: decimalTwo,
            trigger: "blur"
          })],
          'carBrandId': [require(prop('carBrandId'), {
            trigger: "blur",
            type: "number"
          })],
          'carSubBrandId': [require(prop('carSubBrandId'), {
            trigger: "blur",
            type: "number"
          })],
          'carSeriesId': [require(prop('carSeriesId'), {
            trigger: "blur",
            type: "number"
          })],
          'carTypeId': [require(prop('carTypeId'), {
            trigger: "blur",
            type: "number"
          })],
          'carConfig': [require(prop('carConfig'), {
            trigger: "blur"
          })],
          'amount': [require(prop('amount'), {
            trigger: "blur",
            type: "number"
          })],
          'color': [require(prop('color'), {
            trigger: "blur"
          }), {
            validator: isChinese,
            trigger: "blur"
          }],
          'interestRate': [require(prop('interestRate'), {
            trigger: "blur"
          }), {
            validator: max100,
            trigger: "blur"
          }],
          'durationId': [require(prop('durationId'), {
            trigger: "change",
            type: "number"
          })],
          'priceStatus': [require(prop('priceStatus'), {
            trigger: "blur",
            type: "number"
          })],
          'supplierName': [require(prop('supplierName'), {
            trigger: "blur"
          })],
          'supplierCityPid': [require(prop('supplierCityPid'), {
            trigger: "blur",
            type: "number"
          })],
          'supplierCityNid': [require('提车市', {
            trigger: "blur",
            type: "number"
          })],
          'supplierAddress': [require(prop('supplierAddress'), {
            trigger: "blur"
          })],
          'supplierPerson': [require(prop('supplierPerson'), {
            trigger: "blur"
          })],
          'supplierPhone': [require('手机号码', {
            trigger: "blur"
          }), {
            validator: phone,
            trigger: "blur"
          }],
          'accountNumber': [require('收款账号', {
            trigger: "blur"
          }), {
            validator: decimal,
            trigger: "blur"
          }],
          'accountName': [require('开户行名称', {
            trigger: "blur"
          })],
          'openningBank': [require(prop('openningBank'), {
            trigger: "blur"
          })],
          'supplierInfoStatus': [require(prop('supplierInfoStatus'), {
            trigger: "blur",
            type: "number"
          })],
          'businessSysUsersId': [require('业务员', {
            type: "number"
          })],
          'type': [require('订单类型', {
            type: "number"
          })],
          'remark': [require(prop('remark'), {
            trigger: "blur"
          })],
          //'funderId':[require(prop('funderId'),{trigger:"blur",type:"number"})],
          //'spvId':[require(prop('spvId'),{trigger:"blur",type:"number"}),length30()],
          //'orderAuditResults.upperReacherExamineResult':[require(prop('orderAuditResults.upperReacherExamineResult'),{trigger:"blur"}),length30()],
          //'orderAuditResults.earnestExamineResult':[require(prop('orderAuditResults.earnestExamineResult'),{trigger:"blur"}),length30()],
          //'orderAuditResults.supplierEstablishName':[require(prop('orderAuditResults.supplierEstablishName'),{trigger:"blur"}),length30()],
          //'orderAuditResults.supplierEstablishTime':[require(prop('orderAuditResults.supplierEstablishTime'),{type:"data"}),length30()],
          //'orderAuditResults.establishExamineResult':[require(prop('orderAuditResults.establishExamineResult'),{trigger:"blur"}),length30()],
          //'orderAuditResults.resourceProviderName':[require(prop('orderAuditResults.resourceProviderName'),{trigger:"blur"}),length30()],
          //'orderAuditResults.resourceProviderEstablishTime':[require(prop('orderAuditResults.resourceProviderEstablishTime'),{type:"data"}),length30()],
          //'orderAuditResults.resourceProviderExamineResult':[require(prop('orderAuditResults.resourceProviderExamineResult'),{trigger:"blur"}),length30()],
          //'dataChangeRecord':[require(prop('dataChangeRecord'),{trigger:"blur"}),length100()],
          //'orderAuditResults.carAddressExamineResult':[require(prop('orderAuditResults.carAddressExamineResult'),{trigger:"blur"}),length30()],
          //'orderAuditResults.supplierEstablishTime':[ { type: 'date', required: true, message: '请选择时间', trigger: 'change' }]
        },
        hasSaveOrder: false,
        dialogForm: {
          orderAuditResults: {},
          imagUrl: [],
          imagUrl1: [],
          imagUrl2: [],
          imagUrl3: [],
          imagUrl4: [],
          imagUrl5: [],
          imagUrl6: [],
          carBrandId: "",
          type: "",
          businessSysUsersId: "",
          durationId: ""
        },
        //省
        selectProvince: [],
        //是否可编辑车型
        isShowCarType: false,
        //市
        selectCity: [],
        //资金方
        selectFunder: [],
				upSupplier: [], //合同名称
				carPerson:[],			//提车联系人
        //spv
        selectSpvUser: {},
        orderType: {},
        yewuyuan: {},
        ditui: {},
        priceCheckStatus: "",
        carOrderDurationList: {},
        formLabelWidth: '170px',
        cityId: "",
        dialogImageUrl: "",
        dialogVisible: false,
        activeShow: false,
        activeName: "1",
        //审核中
        orderStatusFirstaudit: "FIRSTAUDIT",
        //初审通过
        orderStatusFirstinstance: "FIRSTINSTANCE",
        //二审不通过
        orderStatusSecondreviewfailed: "SECONDREVIEWFAILED",


        //七牛图片上传
        qiniuImage: {
          id: "qiniuImage", //图片预览的id   
          image_uri: [], //图片上传的列表  只含有url地址
        },

        qiniuImage1: {
          id: "qiniuImage1",
          image_uri: []
        },

        qiniuImage2: {
          id: "qiniuImage2",
          image_uri: []
        },

        qiniuImage3: {
          id: "qiniuImage3",
          image_uri: []
        },

        qiniuImage4: {
          id: "qiniuImage4",
          image_uri: []
        },
        qiniuImage5: {
          id: "qiniuImage5",
          image_uri: []
        },
        qiniuImage6: {
          id: "qiniuImage6",
          image_uri: []
        },
        packJson: {
          maxLength: 6, //最大图片数量
          accept: "", //image/gif,image/jpeg,image/jpg,image/png如果是这些，可以不传此参数
          size: 4 //图片大小  单位兆
        },

        packJson1: {
          maxLength: 3,
          accept: "",
          size: 4
        },
        packJson2: {
          maxLength: 10,
          accept: "",
          size: 4
				},
				personCode:"添加",		//区分合同名称是添加还是编辑,默认添加
				Counter:1,						//计数器，配合/区分合同名称是添加还是编辑,一起使用
      }
    },
    props: ['dialogFormVisible', 'query', 'isAdd', 'tableData', 'carOrderId', 'dialogForm.deposit'],
    methods: {
      receiveBrandData(pinpai, zipinpai, chexi, chexing, data) { //依次为 品牌id： 子品牌id:  车系id:  车型id:
        // console.dir('carBrandId---'+this.dialogForm.carTypeId)
        // console.dir('pinpai---'+chexing)

        this.$nextTick(() => {
          this.dialogForm.carBrandId = pinpai;

          this.dialogForm.carSubBrandId = zipinpai;
          this.dialogForm.carSeriesId = chexi;
          this.dialogForm.carTypeId = chexing;
          // alert(data)
          if (data == "") {} else {

            this.dialogForm.specificationName = data.carSpecificationName;
          }

        })
      },
      returnBack() {
        this.dialogFormVisible.bool = false;
      },
      submitConfirmForm(formName) {

        document.getElementById('getFocus').focus()

        this.$refs[formName].validate((valid) => {
          if (valid) {

            this.submitOrder();
          } else {
            this.$nextTick(() => {
              this.activeName = document.getElementsByClassName('is-error')[0].parentElement.getAttribute(
                'index') + "";
              setTimeout(() => {
                this.$message.warning(document.getElementsByClassName('el-form-item__error')[0].innerText);
              }, 500)
              return false;
            })
          }
        });
      },
      //获取初审的订单数据
      queryAuditOrderInfo() {
        agentHttp.get('adminApi/admin/car_order/first_audit_order/view/' + this.carOrderId).then((data) => {
          if (data.success) {
            //省
            this.selectProvince = data.data.province;
            this.dialogForm = data.data.orderInfo;
            //城市如果是空字符串
            if (this.dialogForm.supplierCityPid === "" || this.dialogForm.supplierCityPid == null) {
              this.dialogForm.supplierCityPid = null;
            } else {
              this.dialogForm.supplierCityPid = parseInt(this.dialogForm.supplierCityPid);
            }
            this.cityId = this.dialogForm.supplierCityNid;
            //资金方
            this.selectFunder = data.data.funderUser;

            if (this.dialogForm.orderAuditResults == null) {
              this.dialogForm.orderAuditResults = {};
            } else {
              this.dialogForm.orderAuditResults.examineAptitudePic ? this.qiniuImage4.image_uri = this.dialogForm.orderAuditResults
                .examineAptitudePic.split(',').notempty() : "";
              this.dialogForm.orderAuditResults.resourceProviderPic ? this.qiniuImage5.image_uri = this.dialogForm.orderAuditResults
                .resourceProviderPic.split(',').notempty() : "";
              /*this.dialogForm.orderAuditResults.earnestExamineResult;
              this.dialogForm.orderAuditResults.establishExamineResult;
              this.dialogForm.orderAuditResults.resourceProviderExamineResult;
              this.dialogForm.orderAuditResults.carAddressExamineResult;*/

            }

            //初始化初审审核结果  
            this.dialogForm.orderAuditResults.upperReacherExamineResult = this.dialogForm.orderAuditResults.upperReacherExamineResult ==
              null ? "清晰完整、内容无误" : this.dialogForm.orderAuditResults.upperReacherExamineResult;

            this.dialogForm.orderAuditResults.earnestExamineResult = this.dialogForm.orderAuditResults.earnestExamineResult ==
              null ? "金额与购销合同一致" : this.dialogForm.orderAuditResults.earnestExamineResult;

            this.dialogForm.orderAuditResults.establishExamineResult = this.dialogForm.orderAuditResults.establishExamineResult ==
              null ? "营业状态正常，近期无重大诉讼" : this.dialogForm.orderAuditResults.establishExamineResult;

            this.dialogForm.orderAuditResults.resourceProviderExamineResult = this.dialogForm.orderAuditResults.resourceProviderExamineResult ==
              null ? "营业状态正常，近期无重大诉讼" : this.dialogForm.orderAuditResults.resourceProviderExamineResult;

            this.dialogForm.orderAuditResults.carAddressExamineResult = this.dialogForm.orderAuditResults.carAddressExamineResult ==
              null ? "与打款账号地址一致" : this.dialogForm.orderAuditResults.carAddressExamineResult;

            !this.dialogForm.orderAuditResults.supplierEstablishTime ? this.$set(this.dialogForm.orderAuditResults,
              'supplierEstablishTime', "") : "";
            !this.dialogForm.orderAuditResults.resourceProviderEstablishTime ? this.$set(this.dialogForm.orderAuditResults,
              'resourceProviderEstablishTime', "") : "";

            //初始化业务员
            this.yewuyuan = data.data.yewuyuan;
            //初始化地推人员 
            this.ditui = data.data.ditui;
            //初始化订单类型
            this.orderType = data.data.orderType;
            //初始化合同名称
            this.upSupplier = data.data.upSupplier;
            //默认初始化车辆基本信息
            if (this.dialogForm.priceStatus == null) {
              this.dialogForm.priceStatus = 1;
            }

            //默认初始化上游信息
            if (this.dialogForm.supplierInfoStatus == null) {
              this.dialogForm.supplierInfoStatus = 0;
            }
            //默认初始化地推人员
            if (this.dialogForm.pushSysUsersId == null) {
              this.dialogForm.pushSysUsersId = data.data.orderInfo.dealerPushSysUsersId;
            }
            //默认初始化业务员
            if (this.dialogForm.businessSysUsersId == null) {
              this.dialogForm.businessSysUsersId = data.data.orderInfo.dealerBusinessSysUsersId;
            }


            //加载图片
            this.dialogForm.contracts ? this.qiniuImage.image_uri = this.dialogForm.contracts.split(',').notempty() :
              "";
            this.dialogForm.depositPic ? this.qiniuImage1.image_uri = this.dialogForm.depositPic.split(',').notempty() :
              "";
            this.dialogForm.supplierInfoPic ? this.qiniuImage2.image_uri = this.dialogForm.supplierInfoPic.split(
              ',').notempty() : "";
            this.dialogForm.supplierAddressPic ? this.qiniuImage3.image_uri = this.dialogForm.supplierAddressPic.split(
              ',').notempty() : "";
            this.dialogForm.supplementPic ? this.qiniuImage6.image_uri = this.dialogForm.supplementPic.split(',').notempty() :
              "";
            this.priceCheckStatus = this.dialogForm.priceStatus;

            this.dialogForm.totalPrice = (this.dialogForm.totalPrice - 0).toFixed(2);
            this.dialogForm.paymentAmount = (this.dialogForm.paymentAmount - 0).toFixed(2);
            this.dialogForm.earnest = (this.dialogForm.earnest - 0).toFixed(2);
            this.dialogForm.interestRate = (this.dialogForm.interestRate - 0).toFixed(4);

            this.dialogForm.type == null ? this.dialogForm.type = "" : "";
            this.dialogForm.businessSysUsersId == null ? this.dialogForm.businessSysUsersId = "" : "";
            this.dialogForm.durationId == null ? this.dialogForm.durationId = "" : "";


          }
        })

      },
      //获取市 
      getCity() {
        if (this.dialogForm.supplierCityPid != "" && this.dialogForm.supplierCityPid != null) {
          agentHttp.get('adminApi/admin/dictionary/find_city_new/' + this.dialogForm.supplierCityPid).then((data) => {
            if (data.success) {
              this.selectCity = data.data;
              if (this.cityId != "" && this.cityId != null) {
                this.dialogForm.supplierCityNid = parseInt(this.cityId);
                this.cityId = "";
              } else {
                this.dialogForm.supplierCityNid = this.selectCity[0].nid;

              }
            }
          })

        } else {
          this.dialogForm.supplierCityNid = null;
          this.selectCity = {};
        }

      },
      //spv
      getSpvUser() {
        for (var i = 0; i < this.selectFunder.length; i++) {
          if (this.selectFunder[i].id == this.dialogForm.funderId) {
            if (null != this.selectFunder[i].spv) {
              this.selectSpvUser = this.selectFunder[i].spv;
              this.dialogForm.spvId = parseInt(this.selectFunder[i].spv.id);
              return;
            } else {
              this.dialogForm.spvId = null;
              this.selectSpvUser = {};
            }
          } else {
            this.dialogForm.spvId = null;
            this.selectSpvUser = {};
          }
        }
      },
      //暂存
      saveOrder() {
        if (this.setImageUrl()) {
          this.dialogForm.priceStatus = this.priceCheckStatus;
          agentHttp.postJson('adminApi/admin/car_order/first_audit_order/temporary_save', this.dialogForm).then((data) => {
            if (data.success) {

              this.selectCity = data.data;
              this.$emit('refreshTableData');
              this.dialogFormVisible.bool = false;
              this.$message.success(data.data || "暂存成功");
            }
          }).catch(() => {
            this.dialogForm.priceStatus = this.priceCheckStatus = 1
          })

        }
      },
      submitOrder() {
        if (this.setImageUrl()) {

          this.dialogForm.priceStatus = this.priceCheckStatus;
          // console.dir('carSubBrandId---'+this.dialogForm.carSubBrandId)
          // console.dir('carSeriesId---'+this.dialogForm.carSeriesId)
          // console.dir('carTypeId---'+this.dialogForm.carTypeId)

          agentHttp.postJson('adminApi/admin/car_order/first_audit_order/temporary_sumbit', this.dialogForm).then((data) => {
            if (data.success) {
              this.selectCity = data.data;
              this.$emit('refreshTableData');
              this.dialogFormVisible.bool = false;
              this.$message.success(data.data || "修改成功");
            }
          })
        }
      },

      setImageUrl() {
        this.dialogForm.contracts = this.qiniuImage.image_uri.join(",");
        if (this.dialogForm.contracts.length < 1) {
          this.$message.warning('上游购销合同图片至少一张');
          return false;
        }
        this.dialogForm.depositPic = this.qiniuImage1.image_uri.join(",");
        this.dialogForm.supplierInfoPic = this.qiniuImage2.image_uri.join(",");
        if (this.dialogForm.supplierInfoPic.length < 1) {
          this.$message.warning('供应商收款账号图片至少一张');
          return false;
        }
        this.dialogForm.supplierAddressPic = this.qiniuImage3.image_uri.join(",");
        this.dialogForm.orderAuditResults.examineAptitudePic = this.qiniuImage4.image_uri.join(",");
        this.dialogForm.orderAuditResults.resourceProviderPic = this.qiniuImage5.image_uri.join(",");
        this.dialogForm.supplementPic = this.qiniuImage6.image_uri.join(",");
        return true;

      },
      FormatTwo(val) {

        var value = ((this.dialogForm[val] || "") - 0).toFixed(2);
        if (value.length > 12) {
          this.$message.warning('金额整数长度不能超过9位');
          this.dialogForm[val] = "";
          return;
        }
        this.dialogForm[val] = value == 'NaN' ? "" : value;
      },
      FormatInterestRate(val) {
        var value = ((this.dialogForm[val] || "") - 0).toFixed(4);
        if (value.length > 9) {
          this.$message.warning('利率不能大于100');
          this.dialogForm[val] = "0.0000";
          return;
        }
        this.dialogForm[val] = value == 'NaN' ? "0.0000" : value;
      },
			getPerson(name){			//获取提车联系人
					//根据personCode判断是编辑还是添加
				if(name){
					 agentHttp.post(`adminApi/admin/car_order/up_supplier`,{name}).then((data)=>{
						 	if(data.success){
									this.carPerson  = data.data;
									this.dialogForm.supplierName&&this.dialogForm.supplierPerson&&this.dialogForm.supplierPhone?this.personCode = '编辑' : this.personCode = '添加';
									
										switch(true){
											case this.personCode=='添加':
														this.dialogForm.supplierPerson = this.carPerson[0].name ;
														this.personCode=='编辑' ;
														return 
											case 	this.personCode=='编辑':		//暂时什么都不做
															if(this.carPerson.length>0&&this.Counter>1){			//判断是否是input是否是初次change
																		this.dialogForm.supplierPerson = this.carPerson[0].name ;
																		this.Counter+=1;
																		return 
															}
																	this.Counter+=1;
															return
														break ;
											default :
													return ;

									}
							 }
							 
					 })
			}
									

			},
			carPhone(name){
					//通过name在数组里筛选出手机号码
					if(this.carPerson.length>0){
						const obj = 	this.carPerson.filter(item=>item.name==name);
						this.dialogForm.supplierPhone = obj[0].phone;
				}
			}

    },
    watch: {
      'dialogForm.amount': (newVal, val) => {
        if (newVal.length > 11) {

          this.dialogForm.amount = this.dialogForm.amount.slice(0, 11)
        }
      }
      //借款周期
      /* 'dialogForm.durationId': function (val,oldval) {  
            	for (var i = 0; i < this.dialogForm.carOrderDurationList.length; i++) {
            		debugger;
					if(this.dialogForm.carOrderDurationList[i].id != this.dialogForm.durationId){
						this.dialogForm.durationId = "";	
					}
				}  
            }  */

      //         //购车总价
      //         ,'dialogForm.totalPrice': function (val,oldval) {  
      //         	for (var i = 0; i < this.dialogForm.carOrderDurationList.length; i++) {
      // 	if(this.dialogForm.carOrderDurationList[i].id != this.dialogForm.durationId){
      // 		this.dialogForm.durationId = "";	
      // 	}
      // }  
      //         }  

    },
    computed: {
      //计算保证金
      _deposit: {
        set: function (value) {
          this.dialogForm.deposit = value;
        },
        get: function () {
          this.dialogForm.deposit = (this.dialogForm.totalPrice - this.dialogForm.paymentAmount - this.dialogForm.earnest)
            .toFixed(2);
          return (this.dialogForm.totalPrice - this.dialogForm.paymentAmount - this.dialogForm.earnest).toFixed(2)
        }
      }

    }

  };
</script>
